<template>
	<view class="">
		<view class="sraech-box">
			<u-search placeholder="请输入项目名称" shape="square" v-model="searchData.name" @search="onSearch" :showAction="false" />
		</view>
		<view class="">
			<view class="my-list mt-20">
				<u-list :height="swiperHeight" @scrolltolower="scrolltolower" v-if="dataList.length > 0">
					<u-list-item v-for="(item, index) in dataList" :key="item.id">
						<view class="item fsize-26 flex align-center">
							<image class="img shrink0" :src="item.image"></image>
							<view class="w-100 ml-20 flex justify-between align-center">
								<view class="">
									<view class="fsize-28 fweigh-600">{{item.name}}</view>
									<view class="text-gray">{{item.isDelete?"可服务":"不可服务"}}</view>
								</view>
								
								<view class="">
									<view class="">
										<u-icon name="more-dot-fill" size="20" color="#1890ff" label=" " labelSize="24rpx"
											@click="onClickRow(index)"></u-icon>
									</view>
								</view>
							</view>
						</view>
					</u-list-item>
					<u-loadmore :status="loadmore.status" :icon-type="loadmore.iconType"
						:load-text="loadmore.loadText.loadText" margin-top="0" margin-bottom="20"
						class="coreshop-padding-top-10" />
				</u-list>
			</view>
			<!-- 无数据时默认显示 -->
			<view class="emptybox" v-if="dataList.length == 0">
				<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
			</view>
		</view>
		<!-- 无数据时默认显示 -->
		<view class="emptybox" v-if="dataList.length == 0">
			<u-empty icon-size="150" text="暂无数据" mode="data"></u-empty>
		</view>
		<!-- 操作菜单 -->
		<u-action-sheet :actions="actionSheet.list" @select="selectClick" :title="actionSheet.title"
			:show="actionSheet.show" :closeOnClickAction="true" cancelText="取消" @close="actionSheet.show=false">
		</u-action-sheet>
	</view>
</template>

<script>
	import listHeightMixin from '@/common/computedAltitude.js'
	export default {
		mixins:[listHeightMixin],
		data() {
			return {
				loadmore: {
					status: 'loadmore',
					iconType: 'flower',
					loadText: {
						loadmore: '轻轻上拉',
						loading: '努力加载中',
						nomore: '实在没有了'
					},
				},
				curNow: 0,
				dataList: [],
				searchData: {
					name: '',
					page: 1,
					limit: 10
				},
				actionSheet: {
					show: false,
					title: '',
					list: []
				}
			}
		},
		mounted() {
			let that = this

		},
		onLoad() {
			this.getPageList()
		},
		methods: {
			selectClick(index) {
				let that = this
				let ix = index.ix
				if(index.name==='停止服务'){
					this.$reqJsonPost('',{
						data: false,
						id: this.dataList[ix].id
					}).then(res=>{
						if(res.code === 0){
							this.dataList[ix].onLine = false
						}
					})
				}else if(index.name==='允许服务'){
					this.$reqJsonPost('',{
						data: true,
						id: this.dataList[ix].id
					}).then(res=>{
						if(res.code === 0){
							this.dataList[ix].onLine = true
						}
					})
				}
			},
			onClickRow(index) {
				let item = this.dataList[index]
				this.actionSheet.list = [ {
					name: item.onLine ? '停止服务' : '允许服务',
					id: item.id,
					ix:index
				}]
				this.actionSheet.title = "设置 "+ item.name +" 是否可服务";
				this.actionSheet.show = true
			},
			// 搜索事件
			onSearch() {
				this.searchData.page = 1
				this.getPageList()
			},
			getPageList() {
				this.$reqPost('CoreCmsProjectList', this.searchData).then(res => {
					this.dataList = [...this.dataList, ...res.data]
					if (res.count > this.dataList.length) {
						this.loadmore.status = 'loadmore';
						this.searchData.page++;
					} else {
						// 数据已加载完毕
						this.loadmore.status = 'nomore';
					}
				})
			},
			scrolltolower() {
				if (this.loadmore.status === 'loadmore') {
					this.getPageList();
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.img {
		width: 140rpx;
		height: 140rpx;
		border-radius: 10rpx;
	}
</style>
